package org.geektimes.rest.demo;

import org.geektimes.rest.util.Maps;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;

public class RestClientDemo {

    public static void main(String[] args) {

//        testGet();

        testPost();
    }

    private static void testGet() {
        Client client = ClientBuilder.newClient();
        Response response = client
                .target("http://127.0.0.1:8081/user_web/hello/world")      // WebTarget
                .request() // Invocation.Builder
                .get();                                     //  Response
        String content = response.readEntity(String.class);
        System.out.println(content);
    }

    private static void testPost() {
        Client client = ClientBuilder.newClient();
        Response response = client
                .target("http://127.0.0.1:8081/user_web/user/userLogin")
                .request()
                .post(Entity.json(Maps.of("name", "tangxiaojiu", "password", "1111")));
        String s = response.readEntity(String.class);
        System.out.println(s);
    }
}
